<template>
  <el-dialog title="题目预览" :visible="showDialog" width="80%" center>
    <el-row>
      <el-col :span="6">【题型】: {{ formatQuestionType(questionType) }}</el-col>
      <el-col :span="6">【编号】: {{ id }}</el-col>
      <el-col :span="6">【难度】: {{ formatDifficulty(difficulty) }}</el-col>
      <el-col :span="6">【标签】: {{ tags }}</el-col>
      <el-col :span="6">【学科】: {{ subject }}</el-col>
      <el-col :span="6">【目录】: {{ catalog }}</el-col>
      <el-col :span="6">【方向】: {{ direction }}</el-col>
    </el-row>
    <el-divider></el-divider>
    【题干】：
    <!-- <div>
      <template v-slot="{ row }">
        {{ row.addDate | html2Text }}
      </template>
    </div> -->
    <!-- <template v-if="questionType === '1'">
      <div style="padding-bottom: 5px">
        单选题 选项：（以下选中的选项为正确答案）
      </div>
      <el-radio-group v-model="options" v-for="(item, code) in options" :key="code" >
        <el-radio :label="options.isRight">{{}}</el-radio>
      </el-radio-group>
    </template> -->
    <el-divider></el-divider>
    【参考答案】：
    <el-button type="danger" @click="playVideo">视频答案预览</el-button>
    <video
      ref="video"
      :src="videoURL"
      controls
      style="width: 50%; heigt: 50%; display: none"
    ></video>
    <el-divider></el-divider>
    【答案解析】：
    <span v-html="answer"></span>
    <el-divider></el-divider>
    【题目备注】：
    <span v-html="answerID"></span>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="close">关 闭</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { difficulty, questionType } from '@/api/hmmm/constants.js'

export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number
    },
    questionType: {
      type: String,
      default: '1'
    },
    options: {
      type: Array
    },
    videoURL: {
      type: String,
      default: null
    },
    answerID: {
      type: String,
      default: '无'
    },
    answer: {
      type: String,
      default: '无'
    },
    difficulty: {
      type: String
    },
    tags: {
      type: String
    },
    subject: {
      type: String
    },
    catalog: {
      type: Number
    },
    direction: {
      type: String
    }
  },
  data () {
    return {}
  },
  methods: {
    playVideo () {
      if (this.videoURL) {
        this.$refs.video.style.display = 'block'
      } else {
        this.$refs.video.style.display = 'none'
      }
    },
    formatQuestionType (type) {
      const obj = questionType.find(
        (item) => item.value.toString() === type
      )
      return obj ? obj.label : '未知'
    },
    formatDifficulty (type) {
      const obj = difficulty.find(
        (item) => item.value.toString() === type
      )
      return obj ? obj.label : '未知'
    },
    close () {
      this.$emit('update:showDialog', false)
    }
  }
}
</script>
